package cn.kgc.ubagnet.service.address;

import cn.kgc.ubagnet.mapper.AddressMapper;
import cn.kgc.ubagnet.pojo.Address;
import cn.kgc.ubagnet.pojo.AddressExample;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
@Service
public class AddressServiceImpl implements AddressService{
    @Resource
    AddressMapper addressMapper;


    //根据userId查询所有地址
    @Override
    public List<Address> AddressList(Integer userId) {
        AddressExample example=new AddressExample();
        example.createCriteria().andUseridEqualTo(userId);
        List<Address> addresses = addressMapper.selectByExample(example);
        return addresses;
    }

    //根据Id查询所有地址
    @Override
    public Address AddressById(Integer Id) {
        return addressMapper.selectByPrimaryKey(Id);
    }

    //添加地址
    @Override
    public int AddAddress(Address address) {
        return addressMapper.insertSelective(address);
    }

    //修改地址
    @Override
    public int UpdateAddress(Address address) {
        return addressMapper.updateByPrimaryKeySelective(address);
    }

    //删除地址
    @Override
    public int delAddress(Integer id) {
        return addressMapper.deleteByPrimaryKey(id);
    }

}
